package com.zmn.oms.services.impl.factory;

import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.oms.model.entity.factory.OrderFactory;
import com.zmn.oms.persistence.interfaces.factory.OrderFactoryDao;
import com.zmn.oms.services.interfaces.factory.OrderFactoryService;
import org.springframework.stereotype.Service;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;

/**
 * 类描述：厂商订单
 *
 * @author liuying
 * @date 2018/11/06 11:41
 */
@Service
public class OrderFactoryServiceImpl implements OrderFactoryService {

    @Autowired
    private OrderFactoryDao orderFactoryDao;

    @Override
    public List<OrderFactory> listEsOrderFactoryByOrderIdList(List<Long> orderIdList) {
        return orderFactoryDao.listEsOrderFactoryByOrderIdList(orderIdList);
    }

    @Override
    public OrderFactory findOrderFactoryByKey(Long orderId) {
        return orderFactoryDao.findByKey(orderId);
    }

    @Override
    public Integer updateOrderFactoryByKey(OrderFactory orderFactory) {
        if (orderFactory.getUpdateTime() == null) {
            orderFactory.setUpdateTime(new Date());
        }
        return orderFactoryDao.updateByKey(orderFactory);
    }

    @Override
    public Integer updateReviewByKey(Long fcOrderId) {
        OrderFactory orderFactory = new OrderFactory();
        orderFactory.setFcOrderId(fcOrderId);
        orderFactory.setFcPartReviewStatus(OrderConsts.REVIEW_STATUS_DOING);
        orderFactory.setUpdateTime(new Date());
        return orderFactoryDao.updateReviewByKey(orderFactory);
    }

    @Override
    public Integer updateReviewDefaultByKey(OrderFactory orderFactory) {
        return orderFactoryDao.updateReviewDefaultByKey(orderFactory);
    }
    
    @Override
    public Integer insertOrderFactory(OrderFactory orderFactory) {
        if (orderFactory.getCreateTime() == null) {
            orderFactory.setCreateTime(new Date());
        }
        return orderFactoryDao.insert(orderFactory);
    }

    @Override
    public int updateByKey(OrderFactory orderFactory) {
        return orderFactoryDao.updateByKey(orderFactory);
    }
}
